home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / programs / buf_stuff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  10.4 KB  |  361 lines

  1. #ifndef lint
  2. static char SccsId[]= "@(#)buf_stuff.c    V1.13    3/22/95";
  3. #endif
  4.  
  5. /*
  6. |    file name - buf_stuff.c
  7. |===================================================================
  8. |
  9. |     This program is an example of how you might get data into your
  10. |     views without using the data source facility.  The method
  11. |     accomplishes its task by using the buffers contained in the
  12. |     data source variables (dsv) as a source for the data.  The
  13. |     data is placed into these buffers rather than having to be
  14. |     gathered by the DataViews routines TviReadData or
  15. |     TdlReadData.  This process is loosely referred to as
  16. |     "stuffing the data source buffers".
  17. |
  18. |     Typing a <q|Q> or the right mouse button will exit the program.
  19. |
  20. |===================================================================
  21. */
  22. #include <windows.h>
  23.  
  24. /* DV-Tools header files */
  25. #include "std.h"         /* <stdio.h> etc., scalar & macro definitions */
  26. #include "dvstd.h"         /* public types & constants */
  27. #include "dvtools.h"         /* constants used by T routines */
  28. #include "dvGR.h"         /* constants used by window mgt & GR routines */
  29. #include "VOstd.h"         /* constants used by VO & VOob routines */
  30. #include "Tfundecl.h"         /* T routines (screens, drawports & views) */
  31. #include "VOfundecl.h"         /* VO routines (objects) */
  32.  
  33. /* Constants */
  34. #define  DVPATH            (char *)NULL
  35. #define  DISPFORMS_STB     (char *)NULL
  36. #define  DVDEVICE          (char *)NULL
  37. #define  DVCOLORTABLE      (char *)NULL
  38. #define  VIEW_NAME         "buffer.v"
  39. #define  SCREEN_VIEWPORT   (RECTANGLE *)NULL
  40. #define  DRAWING_VIEWPORT  (RECTANGLE *)NULL
  41.  
  42. /*
  43.  *   Declare the pointers to be used for stuffing the buffers.
  44.  */
  45. LOCAL char *TextBufPtr;        /* data buffer of dsv named Text Var */
  46. LOCAL float *FloatBufPtr;    /* data buffer of dsv named Float Var */
  47. LOCAL int counter = 0;        /* init counter used in UpdateData routine */
  48.  
  49. /* Local forward function declarations */
  50. LOCAL ADDRESS GetDsvBuffers V_P_ ((DATASOURCE ds, DSVAR dsvar, 
  51.                    ADDRESS argblock));
  52. LOCAL void UpdateData V_P_ ((void));
  53.  
  54.  
  55. /*
  56.  *   MAIN PROGRAM
  57.  */
  58. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  59.                      LPSTR lpCmdLine,  int nCmdShow  )
  60. {
  61.   INT argc = 0; 
  62.   CHAR **argv; 
  63.  
  64.   /*
  65.    *  program arguments
  66.    *    argv[1] - display device (default is DVDEVICE)
  67.    */
  68.  
  69.   /* Define & initialize device name and view filename */
  70.   char *device_name = DVDEVICE;    /* default device name */
  71.   char *view_name = VIEW_NAME;    /* default view name */
  72.  
  73.   /* Define display variables */
  74.   OBJECT screen;       /* display device, the window */
  75.   DRAWPORT drawport;       /* how & where to display picture, picture frame */
  76.   VIEW view;               /* picture representation of the view file */
  77.  
  78.   /* Control loop variables */
  79.   OBJECT location;        /* the event representation */
  80.  
  81.   /* Other variables */
  82.   DATASOURCELIST dsl;        /* list of data sources */
  83.   int Quit = NO;        /* flag to quit program */
  84.  
  85.   /*-----------------
  86.    *   Initialization
  87.    *
  88.    *   TInit:    perform the initialization of DV-Tools
  89.    *             TInit reads your configuration file and any
  90.    *             environment variables or logical names set.
  91.    */
  92.   make_argv(&argc,&argv,GetCommandLine());
  93.   TInit( DVPATH, DISPFORMS_STB );
  94.  
  95.   /*
  96.    *   TscOpenSet:  opens a device as a screen object using
  97.    *                specified attributes
  98.    */
  99.   if (argc > 1)
  100.     device_name = argv[1];
  101.   screen = TscOpenSet (device_name, DVCOLORTABLE,
  102.                V_X_EXPOSURE_BLOCK, YES,
  103.                V_ACTIVE_CURSOR, V_END_OF_LIST);
  104.   if (!screen)
  105.     {
  106.       printf ("Must specify device on command line or");
  107.       printf (" in DataViews configuration file.\n");
  108.       S_EXIT (EXIT_ERR);
  109.     }
  110.  
  111.   /*
  112.    *   VOscWinEventMask:  sets the screen's window event mask
  113.    */
  114.   VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS | V_EXPOSE | V_RESIZE,
  115.             (ULONG) 0);
  116.  
  117.   /*
  118.    *   TviLoad:   Load a view in from a file,
  119.    *              user supplied view or default view of buffer.v
  120.    */
  121.   view = TviLoad (view_name);
  122.   if (!view)
  123.     {
  124.       printf ("Could not load view from file ");
  125.       printf ("%s.\n", view_name);
  126.       S_EXIT (EXIT_ERR);
  127.     }
  128.  
  129.   /*
  130.    *  TviGetDataSourceList:  Gets a view's data source list
  131.    *  TdlForEachVar:         Traverses all data source variables
  132.    *
  133.    *  Traverse all data source variables found in the view's
  134.    *  data source list and call the function GetDsvBuffers
  135.    *  for each one.
  136.    */
  137.   dsl = TviGetDataSourceList (view);
  138.   TdlForEachVar (dsl, GetDsvBuffers, (ADDRESS) NULL);
  139.  
  140.   /*
  141.    *   TdpCreate: Create a drawport.
  142.    *              The drawport is attached to the screen object
  143.    *              specified while view specifies the view to be
  144.    *              displayed on the screen.
  145.    *
  146.    *   UpdateData:  Update data source buffers used by dynamic
  147.    *                objects in view.
  148.    */
  149.   drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
  150.   UpdateData ();
  151.  
  152.   /*
  153.    *   TscErase: Erase the entire screen in the default
  154.    *             background color
  155.    *   TdpDraw:  Draw the contents of the drawport
  156.    */
  157.   TscErase (screen);
  158.   TdpDraw (drawport);
  159.  
  160.   /*--------------------
  161.    *   Control loop
  162.    *
  163.    *   Poll the event queue for locator events. If the key
  164.    *   represents the character 'q' or 'Q' or the right
  165.    *   mouse button then quit the program. Meanwhile,
  166.    *   continue to update the data source buffers and draw the
  167.    *   next iteration of the drawport.
  168.    */
  169.   FOREVER
  170.   {
  171.     /*
  172.      *  VOloWinEventPoll:  Poll for the next window event.
  173.      *                     The polling mode used is V_WAIT.
  174.      *                     Therefore, VOloWinEventPoll does not
  175.      *                     return until a masked event is
  176.      *                     generated.  V_WAIT always produces
  177.      *                     a valid location object.
  178.      */
  179.     location = VOloWinEventPoll (V_WAIT);
  180.  
  181.     /*
  182.      *  VOloType:  returns the type of event.  These types
  183.      *             match event types specified in VOscWinEventMask.
  184.      */
  185.     switch (VOloType (location))
  186.       {
  187.  
  188.       case V_RESIZE:
  189.     /*
  190.          *  The window size has been changed.
  191.          *  TscReset:  Resets all screen drawports after
  192.          *             window resizing
  193.          */
  194.     TscReset (screen);
  195.     break;
  196.  
  197.       case V_EXPOSE:
  198.     /*
  199.          *  VOloRegion:  Returns a rectangle representing the
  200.          *               exposed region on the screen.
  201.          *  TscRedraw:   After erasing, redraws all the drawports
  202.          *               in the screen.
  203.          *  A portion of the window has been exposed and needs
  204.          *  to be redrawn.
  205.          */
  206.     TscRedraw (screen, VOloRegion (location));
  207.     break;
  208.  
  209.       case V_KEYPRESS:
  210.     /*
  211.          *  Check key selected.
  212.          *  VOloKeySym:  Returns the key symbol value of the
  213.          *               location object
  214.          *
  215.          *  If the key symbol represents the characters 'q'
  216.          *  or 'Q' then quit the program.
  217.          */
  218.     switch (VOloKeySym (location))
  219.       {
  220.       case 'q':
  221.       case 'Q':
  222.         Quit = YES;
  223.         break;
  224.  
  225.       default:
  226.         /*
  227.              *  TdpDrawNext: Update all dynamic objects within a
  228.              *               drawport's view.
  229.              *  Update internal data buffers and draw next iteration
  230.              */
  231.         UpdateData ();
  232.         TdpDrawNext (drawport);
  233.         break;
  234.       }
  235.     break;
  236.  
  237.       case V_BUTTONPRESS:
  238.     /*
  239.          *  VOloButton:  Returns the button that was pressed
  240.          *
  241.          *  The right mouse button exits the program.
  242.          */
  243.     if (VOloButton (location) == 3)
  244.       Quit = YES;
  245.     else
  246.       {
  247.         /*
  248.              *  TdpDrawNext: Update all dynamic objects within a
  249.              *               drawport's view.
  250.              *  Update internal data buffers and draw next iteration
  251.              */
  252.         UpdateData ();
  253.         TdpDrawNext (drawport);
  254.       }
  255.     break;
  256.  
  257.       default:
  258.     break;
  259.       }
  260.  
  261.     /* exit the program */
  262.     if (Quit == YES)
  263.       break;
  264.   }
  265.  
  266.   /*--------------------
  267.    *   Termination
  268.    *
  269.    *   TscErase:     Erase the entire screen in the default
  270.    *                 background color
  271.    *   TdpDestroy:   Destroy the drawport,
  272.    *   TviDestroy:   Destroy the view, freeing the allocated memory
  273.    *   TscCloseCurrentScreen:  Close the current display screen
  274.    *   TTerminate:   Perform the clean-up for DV-Tools
  275.    */
  276.   TscErase (screen);
  277.   TdpDestroy (drawport);
  278.   TviDestroy (view);
  279.   TscCloseCurrentScreen ();
  280.   TTerminate ();
  281.   return EXIT_OK;
  282. }
  283.  
  284.  
  285. /*
  286.  *----------------
  287.  *   GetDsvBuffers -- get the address of the data buffers
  288.  *     pointed to by the data source variable.  Store the
  289.  *     address of this data buffer which will be used
  290.  *     later when updating dynamic objects.
  291.  */
  292. /*ARGSUSED*/
  293. LOCAL ADDRESS 
  294. GetDsvBuffers (ds, dsvar, argblock)
  295.      DATASOURCE ds;
  296.      DSVAR dsvar;
  297.      ADDRESS argblock;
  298. {
  299.   char *name;            /* data source variable name */
  300.  
  301.   /*
  302.    *  TdsvGetName:  Gets the name of a data source variable
  303.    *
  304.    *  Obtain the address of the data source variable's
  305.    *  data buffer.  The application will update the
  306.    *  contents of the data buffer pointed to by this
  307.    *  address.  This is referred to as stuffing the
  308.    *  buffers.
  309.    */
  310.   name = TdsvGetName (dsvar);
  311.   if (strcmp (name, "Text Var") == 0)
  312.     TextBufPtr = TdsvGetBuffer (dsvar);
  313.   else if (strcmp (name, "Float Var") == 0)
  314.     FloatBufPtr = (float *) TdsvGetBuffer (dsvar);
  315.  
  316.   return V_CONTINUE_TRAVERSAL;
  317. }
  318.  
  319.  
  320. /*
  321.  *-------------
  322.  *   UpdateData -- updates the values in the buffers of the
  323.  *     dynamic elements of the view.
  324.  */
  325. LOCAL void
  326. UpdateData ()
  327. {
  328.   LOCAL char *mycharbuf[] =
  329.     {
  330.     "1st time",
  331.     "2nd time",
  332.     "3rd time",
  333.     "4th time",
  334.     "5th time",
  335.     "6th time",
  336.     "7th time",
  337.     "8th time",
  338.     "9th time",
  339.     "10th time"
  340.     };
  341.  
  342.   /*
  343.    *  Increment the counter by one, copy the character string based
  344.    *  on the counter value to the data source buffer TextBufPtr.
  345.    */
  346.   if (++counter > 10)
  347.     counter = 1;
  348.  
  349.   strcpy (TextBufPtr, mycharbuf[counter-1]);
  350.  
  351.   /*
  352.    *  Set the data source variable FloatBufPtr by incrementing its
  353.    *  current value by .1.  Reset FloatBufPtr to zero when the
  354.    *  the counter has been reset.
  355.    */
  356.   if (counter == 1)
  357.     *FloatBufPtr = 0.0;
  358.   else
  359.     *FloatBufPtr += 0.1;
  360. }
  361.